package com.wl2o2o.lanqiao.xzfourteen;
/** 
* @author : WLei224
* @date ：2023年4月2日 下午6:14:08 
* 
*/


import java.util.Scanner;
import java.util.Stack;

public class 括号匹配 {
 public static void main(String[] args) {
     Scanner scan = new Scanner(System.in);
     while(scan.hasNext()){
         String bds = scan.next();
         Stack<Character> s = new Stack<>();
         if(bds.equals("#"))break;
         //将括号表达式转换为数组
         char[] c = bds.toCharArray();
         int i = 0;
         //将左括号循环pop进栈
         for( ; i < c.length; i++){
             if(c[i] == '(' || c[i] == '[')s.push(c[i]);
             else if(c[i] == ']'){
                 if(s.isEmpty() || s.pop() != '[') break;
             } 
             else if(c[i] == ')'){
                 if(s.isEmpty() || s.pop() != '(') break;
             }
             System.out.println(s);
         }
         if(s.size() == 0 && i == c.length) System.out.println("YES");
         else System.out.println("NO");
     }
     
     scan.close();
 }

}